<?php
declare (strict_types=1);

namespace app\command;

use app\api\service\WechatService;
use app\model\PayRecord;
use think\console\Command;
use think\console\Input;
use think\console\Output;

class PayrecordSyncDeviceType extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('payrecord-sync-device-type')
            ->setDescription('更新历史订单记录表设备类型字段');
    }

    protected function execute(Input $input, Output $output)
    {
        PayRecord::where('device_type',0)
            ->chunk(1000,function ($items){
                foreach ($items as $item){
                    $item->device_type = WechatService::getDeviceType($item->user->mobile_system ?? '');
                    if ($item->save()){
                        dump($item->id);
                    }
                }
            },'id','DESC');
    }
}
